import sys

MSGS = ("aa asd", "aa    ")

def strxor(a, b):     # xor two strings of different lengths
    if len(a) > len(b):
        return "".join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a[:len(b)], b)])
    else:
        return "".join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b[:len(a)])])

def random(size=16):
    return open("/dev/urandom").read(size)

def encrypt(key, msg):
    c = strxor(key, msg)
    print
    print c.encode('hex')
    return c

def main():
    key = random(1024)
    ciphertexts = [encrypt(key, msg) for msg in MSGS]
    return ciphertexts


lst = []
for x in range(26):
    lst.append(chr(x + ord('a')))
for x in range(26):
    lst.append(chr(x + ord('A')))
for x in lst:
    print x + " xor ','=" + strxor(x, " ").encode('hex')
for x in lst:
    print x + " xor ','=" + strxor(x, ",").encode('hex')
for x in lst:
    print x + " xor '.'=" + strxor(x, ".").encode('hex')
for x in lst:
    print x + " xor '!'=" + strxor(x, "!").encode('hex')
for x in lst:
    print x + " xor '?'=" + strxor(x, "?").encode('hex')
